package logic

import (
	"context"
	"profile/userrpc/userrpc"

	"profile/api/internal/svc"
	"profile/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateLogic {
	return &UserUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdateLogic) UserUpdate(req *types.UserUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.UserRpc.UserUpdate(l.ctx, &userrpc.UserUpdateRequest{
		Id:       req.Id,
		Sex:      req.Sex,
		Birthday: req.Birthday,
	})
	if err != nil {
		return &types.Response{
			Code:    0,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "用户修改成功",
		Data:    update,
	}, nil
}
